import {
  Entity,
  PrimaryGeneratedColumn,
  Column,
  ManyToOne,
  JoinColumn,
  BeforeInsert,
  BeforeUpdate,
} from 'typeorm';
import { Stage } from '../../stage/entities/stage.entity'; // 请确保路径正确
import { EventTypeEnum } from 'src/common/constant/enums';

@Entity('stage_events')
export class StageEvent {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({ name: 'stage_id' })
  stageId: number;

  @Column({ name: 'event_order' })
  eventOrder: number;

  @Column({ name: 'type' })
  type: EventTypeEnum;

  @Column({ name: 'createBy' })
  createBy: number;

  @Column({ name: 'createTime', type: 'datetime' })
  createTime: Date;

  @Column({ name: 'updateBy' })
  updateBy: number;

  @Column({ name: 'updateTime', type: 'datetime' })
  updateTime: Date;

  @ManyToOne(() => Stage, (stage) => stage.stageEvents)
  @JoinColumn({ name: 'stage_id' })
  stage: Stage;

  @BeforeInsert()
  BeforeInsert() {
    this.createTime = new Date();
    this.updateTime = this.createTime;
  }

  @BeforeUpdate()
  BeforeUpdate() {
    this.updateTime = new Date();
  }
}
